package com.jl.jlapp.mvp.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter.OnItemClickListener;
import com.jl.jlapp.R;
import com.jl.jlapp.adapter.DiscountAdapter;
import com.jl.jlapp.eneity.ActivitysAndCouponsByGoodsMsgModel;
import com.jl.jlapp.eneity.ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean;
import com.jl.jlapp.eneity.ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean.UserCouponsBean;
import com.jl.jlapp.eneity.ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean.UserCouponsBean.CouponInformationBean;
import com.jl.jlapp.eneity.DiscountModel;
import com.jl.jlapp.eneity.UserCouponInfosModel;
import com.jl.jlapp.eneity.UserCouponInfosModel.ResultDataBean.UsableCouponBean;
import com.jl.jlapp.mvp.activity.LoginActivity;
import com.jl.jlapp.mvp.activity.OrderSubmitActivity;
import com.jl.jlapp.nets.Api;
import com.jl.jlapp.nets.CommonObserver;
import com.jl.jlapp.nets.Net;
import com.jl.jlapp.nets.Transformer;

import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

import java.util.ArrayList;
import java.util.List;

public class DiscountFragment extends LazyLoadFragment {
    private static final String EXTRA_TYPE = "extra_type";
    public static final int TYPE_UNUSEABLE = 2;
    public static final int TYPE_USEABLE = 1;
    ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean.UserCouponsBean.CouponInformationBean couponInformationBean;
    ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean couponsBean;
    @BindView(R.id.lrv_discount_list)
    RecyclerView lrvDiscountList;
    private List<DiscountModel> modelList;
    @BindView(R.id.no_coupon_show)
    RelativeLayout noCouponShow;
    public OnGetCouponMsg onGetCouponMsg;
    public setOnClickCouponItem setOnClickCouponItem;
    List<ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean> shouldShowUnUsableCouponsBeanList = new ArrayList();
    List<ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean> shouldShowUsableCouponsBeanList = new ArrayList();
    int type = 1;
    private DiscountAdapter unUsadleDiscountAdapter;
    Unbinder unbinder;
    List<UserCouponInfosModel.ResultDataBean.UsableCouponBean> usableCouponBeans = new ArrayList();
    List<ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean> usableCouponsBeanList;
    private DiscountAdapter usadleDiscountAdapter;
    ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean.UserCouponsBean userCouponsBean;
    int userId = 0;

    private void initDatas(int paramInt) {
        switch (paramInt) {
            case 1:
                setUsableData();
                if (this.onGetCouponMsg != null) {
                    setUnusableCoupons();
                    this.onGetCouponMsg.onGetCouponMsg(this.shouldShowUsableCouponsBeanList.size(), this.shouldShowUnUsableCouponsBeanList.size());
                }
                if (this.shouldShowUsableCouponsBeanList.size() > 0) {
                    this.lrvDiscountList.setVisibility(View.VISIBLE);
                    this.noCouponShow.setVisibility(View.GONE);
                    if (this.usadleDiscountAdapter == null) {
                        this.lrvDiscountList.setLayoutManager(new LinearLayoutManager(getActivity()));
                        this.usadleDiscountAdapter = new DiscountAdapter(R.layout.item_discount, this.shouldShowUsableCouponsBeanList);
                        this.usadleDiscountAdapter.setType(paramInt);
                        this.lrvDiscountList.setAdapter(this.usadleDiscountAdapter);
                        this.usadleDiscountAdapter.setOnItemClickListener(new OnItemClickListener() {
                            public void onItemClick(BaseQuickAdapter paramAnonymousBaseQuickAdapter, View paramAnonymousView, int paramAnonymousInt) {
                                TextView tv_discount_money = (TextView) paramAnonymousView.findViewById(R.id.tv_discount_money);
                                TextView tv_discount_condition = (TextView) paramAnonymousView.findViewById(R.id.tv_discount_condition);
                                paramAnonymousInt = ((ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean) DiscountFragment.this.shouldShowUsableCouponsBeanList.get(paramAnonymousInt)).getUserCoupons().getId();
                                double d = Double.parseDouble(tv_discount_money.getText().toString().trim());
                                String trim = tv_discount_condition.getText().toString().trim();
                                if (DiscountFragment.this.setOnClickCouponItem != null) {
                                    DiscountFragment.this.setOnClickCouponItem.onClickCouponItem(paramAnonymousInt, d, trim);
                                }
                            }
                        });
                        return;
                    }
                    this.usadleDiscountAdapter.setType(paramInt);
                    this.usadleDiscountAdapter.notifyDataSetChanged();
                    return;
                }
                this.lrvDiscountList.setVisibility(View.GONE);
                this.noCouponShow.setVisibility(View.VISIBLE);
                break;
        }
    }

    public static DiscountFragment newInstance(int paramInt1, int paramInt2) {
        DiscountFragment localDiscountFragment = new DiscountFragment();
        Bundle localBundle = new Bundle();
        localBundle.putInt("extra_type", paramInt1);
        localBundle.putInt("userId", paramInt2);
        localDiscountFragment.setArguments(localBundle);
        return localDiscountFragment;
    }

    private void setUsableData() {
        this.shouldShowUsableCouponsBeanList.clear();
        int i = 0;
        while (i < this.usableCouponsBeanList.size()) {
            this.couponsBean = new ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean();
            this.userCouponsBean = new ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean.UserCouponsBean();
            this.userCouponsBean.setId(((ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean) this.usableCouponsBeanList.get(i)).getUserCoupons().getId());
            this.userCouponsBean.setUserId(((ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean) this.usableCouponsBeanList.get(i)).getUserCoupons().getUserId());
            this.userCouponsBean.setCouponInformationId(((ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean) this.usableCouponsBeanList.get(i)).getUserCoupons().getCouponInformationId());
            this.userCouponsBean.setStatus(((ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean) this.usableCouponsBeanList.get(i)).getUserCoupons().getStatus());
            this.userCouponsBean.setGetTime(((ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean) this.usableCouponsBeanList.get(i)).getUserCoupons().getGetTime());
            this.couponInformationBean = new ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean.UserCouponsBean.CouponInformationBean();
            this.couponInformationBean.setId(((ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean) this.usableCouponsBeanList.get(i)).getUserCoupons().getCouponInformation().getId());
            this.couponInformationBean.setIdentifier(((ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean) this.usableCouponsBeanList.get(i)).getUserCoupons().getCouponInformation().getIdentifier());
            this.couponInformationBean.setName(((ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean) this.usableCouponsBeanList.get(i)).getUserCoupons().getCouponInformation().getName());
            this.couponInformationBean.setPrice(((ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean) this.usableCouponsBeanList.get(i)).getUserCoupons().getCouponInformation().getPrice());
            this.couponInformationBean.setTotal(((ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean) this.usableCouponsBeanList.get(i)).getUserCoupons().getCouponInformation().getTotal());
            this.couponInformationBean.setUseLimit(((ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean) this.usableCouponsBeanList.get(i)).getUserCoupons().getCouponInformation().getUseLimit());
            this.couponInformationBean.setCount(((ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean) this.usableCouponsBeanList.get(i)).getUserCoupons().getCouponInformation().getCount());
            this.couponInformationBean.setState(((ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean) this.usableCouponsBeanList.get(i)).getUserCoupons().getCouponInformation().getState());
            this.couponInformationBean.setRules(((ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean) this.usableCouponsBeanList.get(i)).getUserCoupons().getCouponInformation().getRules());
            this.couponInformationBean.setBeginValidityTime(((ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean) this.usableCouponsBeanList.get(i)).getUserCoupons().getCouponInformation().getBeginValidityTime());
            this.couponInformationBean.setEndValidityTime(((ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean) this.usableCouponsBeanList.get(i)).getUserCoupons().getCouponInformation().getEndValidityTime());
            this.couponInformationBean.setBeginTime(((ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean) this.usableCouponsBeanList.get(i)).getUserCoupons().getCouponInformation().getBeginTime());
            this.couponInformationBean.setEndTime(((ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean) this.usableCouponsBeanList.get(i)).getUserCoupons().getCouponInformation().getEndTime());
            this.couponInformationBean.setOperatorIdentifier(((ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean) this.usableCouponsBeanList.get(i)).getUserCoupons().getCouponInformation().getOperatorIdentifier());
            this.couponInformationBean.setOperatorTime(((ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean) this.usableCouponsBeanList.get(i)).getUserCoupons().getCouponInformation().getOperatorTime());
            this.userCouponsBean.setCouponInformation(this.couponInformationBean);
            this.couponsBean.setUserCoupons(this.userCouponsBean);
            this.couponsBean.setAfterDiscountMoney(((ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean) this.usableCouponsBeanList.get(i)).getAfterDiscountMoney());
            this.shouldShowUsableCouponsBeanList.add(this.couponsBean);
            i += 1;
        }
    }

    public void getCouponInfoByUserId(int paramInt) {
        Net.get().getCouponInfoByUserId(paramInt).compose(Transformer.<UserCouponInfosModel>switchSchedulers())
                .subscribe(new CommonObserver<UserCouponInfosModel>() {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(UserCouponInfosModel userCouponInfosModel) {

                    }
                });
    }

    public int initLayout() {
        return R.layout.fragment_discount;
    }

    public void initViews(View paramView) {
        Bundle localBundle = getArguments();
        if ((localBundle == null) || (!localBundle.containsKey("extra_type"))) {
            throw new IllegalArgumentException("NoticeListFragment must be created by type args");
        }
        this.type = localBundle.getInt("extra_type", 1);
        this.userId = localBundle.getInt("userId", 0);
        this.unbinder = ButterKnife.bind(this, paramView);
    }

    public void loadData() {
        if (this.userId > 0) {
            getCouponInfoByUserId(this.userId);
            this.usableCouponsBeanList = OrderSubmitActivity.shouldShowCouponsBeanList;
            return;
        }
        Toast.makeText(getContext(), "您还未登录，请先登录。", Toast.LENGTH_SHORT).show();
        startActivity(new Intent(getContext(), LoginActivity.class));
    }

    public void setOnGetCouponMsg(OnGetCouponMsg paramOnGetCouponMsg) {
        this.onGetCouponMsg = paramOnGetCouponMsg;
    }

    public void setSetOnClickCouponItem(setOnClickCouponItem paramsetOnClickCouponItem) {
        this.setOnClickCouponItem = paramsetOnClickCouponItem;
    }

    public void setUnusableCoupons() {
        this.shouldShowUnUsableCouponsBeanList.clear();
        if (this.usableCouponsBeanList.size() > 0) {
            int i = 0;
            if (i < this.usableCouponsBeanList.size()) {
                int j = 0;
                for (; ; ) {
                    if (j < this.usableCouponBeans.size()) {
                        if (((ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean) this.usableCouponsBeanList.get(i)).getUserCoupons().getId() == ((UserCouponInfosModel.ResultDataBean.UsableCouponBean) this.usableCouponBeans.get(j)).getId()) {
                            this.usableCouponBeans.remove(j);
                        }
                    } else {
                        i += 1;
                        break;
                    }
                    j += 1;
                }
            }
        }
        int i = 0;
        while (i < this.usableCouponBeans.size()) {
            this.couponsBean = new ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean();
            this.userCouponsBean = new ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean.UserCouponsBean();
            this.userCouponsBean.setId(((UserCouponInfosModel.ResultDataBean.UsableCouponBean) this.usableCouponBeans.get(i)).getId());
            this.userCouponsBean.setUserId(((UserCouponInfosModel.ResultDataBean.UsableCouponBean) this.usableCouponBeans.get(i)).getUserId());
            this.userCouponsBean.setCouponInformationId(((UserCouponInfosModel.ResultDataBean.UsableCouponBean) this.usableCouponBeans.get(i)).getCouponInformationId());
            this.userCouponsBean.setStatus(((UserCouponInfosModel.ResultDataBean.UsableCouponBean) this.usableCouponBeans.get(i)).getStatus());
            this.userCouponsBean.setGetTime(((UserCouponInfosModel.ResultDataBean.UsableCouponBean) this.usableCouponBeans.get(i)).getGetTime());
            this.couponInformationBean = new ActivitysAndCouponsByGoodsMsgModel.ResultDataBean.CouponsBean.UserCouponsBean.CouponInformationBean();
            this.couponInformationBean.setId(((UserCouponInfosModel.ResultDataBean.UsableCouponBean) this.usableCouponBeans.get(i)).getCouponInformation().getId());
            this.couponInformationBean.setIdentifier(((UserCouponInfosModel.ResultDataBean.UsableCouponBean) this.usableCouponBeans.get(i)).getCouponInformation().getIdentifier());
            this.couponInformationBean.setName(((UserCouponInfosModel.ResultDataBean.UsableCouponBean) this.usableCouponBeans.get(i)).getCouponInformation().getName());
            this.couponInformationBean.setPrice(((UserCouponInfosModel.ResultDataBean.UsableCouponBean) this.usableCouponBeans.get(i)).getCouponInformation().getPrice());
            this.couponInformationBean.setTotal(((UserCouponInfosModel.ResultDataBean.UsableCouponBean) this.usableCouponBeans.get(i)).getCouponInformation().getTotal());
            this.couponInformationBean.setUseLimit(((UserCouponInfosModel.ResultDataBean.UsableCouponBean) this.usableCouponBeans.get(i)).getCouponInformation().getUseLimit());
            this.couponInformationBean.setCount(((UserCouponInfosModel.ResultDataBean.UsableCouponBean) this.usableCouponBeans.get(i)).getCouponInformation().getCount());
            this.couponInformationBean.setState(((UserCouponInfosModel.ResultDataBean.UsableCouponBean) this.usableCouponBeans.get(i)).getCouponInformation().getState());
            this.couponInformationBean.setRules(((UserCouponInfosModel.ResultDataBean.UsableCouponBean) this.usableCouponBeans.get(i)).getCouponInformation().getRules());
            this.couponInformationBean.setBeginValidityTime(((UserCouponInfosModel.ResultDataBean.UsableCouponBean) this.usableCouponBeans.get(i)).getCouponInformation().getBeginValidityTime());
            this.couponInformationBean.setEndValidityTime(((UserCouponInfosModel.ResultDataBean.UsableCouponBean) this.usableCouponBeans.get(i)).getCouponInformation().getEndValidityTime());
            this.couponInformationBean.setBeginTime(((UserCouponInfosModel.ResultDataBean.UsableCouponBean) this.usableCouponBeans.get(i)).getCouponInformation().getBeginTime());
            this.couponInformationBean.setEndTime(((UserCouponInfosModel.ResultDataBean.UsableCouponBean) this.usableCouponBeans.get(i)).getCouponInformation().getEndTime());
            this.couponInformationBean.setOperatorIdentifier(((UserCouponInfosModel.ResultDataBean.UsableCouponBean) this.usableCouponBeans.get(i)).getCouponInformation().getOperatorIdentifier());
            this.couponInformationBean.setOperatorTime(((UserCouponInfosModel.ResultDataBean.UsableCouponBean) this.usableCouponBeans.get(i)).getCouponInformation().getOperatorTime());
            this.userCouponsBean.setCouponInformation(this.couponInformationBean);
            this.couponsBean.setUserCoupons(this.userCouponsBean);
            this.shouldShowUnUsableCouponsBeanList.add(this.couponsBean);
            i += 1;
        }
    }

    public static abstract interface OnGetCouponMsg {
        public abstract void onGetCouponMsg(int paramInt1, int paramInt2);
    }

    public static abstract interface setOnClickCouponItem {
        public abstract void onClickCouponItem(int paramInt, double paramDouble, String paramString);
    }
}


/* Location:              /Users/davidzhang/Documents/decompileApk/jlfood-dex2jar.jar!/com/jl/jlapp/mvp/fragment/DiscountFragment.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */